﻿
// 无实体单例

namespace Tools.Singleton
{
    public class Singleton<T> where T : new()
    {
        private static T _instance;
        private static object _lock = new object();

        public static T instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_lock)
                    {
                        _instance = new T();
                    }
                }
                return _instance;
            }
        }
    }
}
// 举个栗子
namespace Tools.Singleton.Test
{
    public class ClassName1 : Singleton<ClassName1>
    {
        // 。。。。。。
    }
}